package com.lms.dao;

import java.sql.Date;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.HibernateTemplate;


import com.lms.domain.LoginDetails;
import com.lms.domain.UserDetails;
import com.lms.web.Login;


public class lmsDAOImpl implements lmsDAO {

	private HibernateTemplate hibernateTemplate;
	private LoginDetails loginDetails;

	public LoginDetails getLoginDetails() {
		return loginDetails;
	}

	public void setLoginDetails(LoginDetails loginDetails) {
		this.loginDetails = loginDetails;
	}

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.hibernateTemplate = new HibernateTemplate(sessionFactory);
	}

	

	public void insertIntoLoginDetails(UserDetails userDetails) {
		loginDetails= new LoginDetails();
		loginDetails.setEmployeeId(userDetails.getEmployeeId());
		loginDetails.setPassword("qwerty");
		loginDetails.setRole("user");
		hibernateTemplate.saveOrUpdate(loginDetails);
	}

	@SuppressWarnings("unchecked")
	public List<Login> getLogin(Login login) {

		return hibernateTemplate.find(
				"from LoginDetails where employeeId=? and password=?",
				login.getEmployeeId(), login.getPassword());

		// return hibernateTemplate.find("from LoginDetails");;
	}

	
	public void changePassword(LoginDetails newPass) {
		hibernateTemplate.saveOrUpdate(newPass);
	}

}
